<?php
class DbConnection
{
	private $host;
	private $user;
	private $database;
	
	// host value
	public function setHost($host)
	{
		$this->host = $host;
	}
    public function getHost()
    {
        return $this->host;
    }
		
	// user value
	public function setUser($user)
	{
		$this->user = $user;
	}
	public function getUser()
	{
		return $this->user;
	}
	
	// selected database value
	public function setDatabase($database)
	{
		$this->database = $database;
	}
	public function getDatabase()
	{
		return $this->database;
	}

	public function Error()
	{
		return "<h2>MySQL Error! ".mysql_error()."</h2>";
	}
	
	// check connection to db
	public function Connect()
	{
		if ((!mysql_connect($this->getHost(), $this->getUser()))||(!mysql_select_db($this->getDatabase())))
		{
			$this->Error();
			exit;
		}
	}
	
	// constructor & destructor
	public function __construct($_host,$_user,$_db)
    {
		$this->setHost($_host);
		$this->setUser($_user);
		$this->setDatabase($_db);
		
		$this->Connect();
    }
}
?>